package test.run;

import mythread.MyThread;


/**
 * 暂停线程
 * 意味着此线程还可以恢复运行。在Java多线程中，可以使用suspend()方法暂停线程，
 * 使用resume()方法恢复线程的执行。
 */
public class Run {

	public static void main(String[] args) {

		try {
			MyThread thread = new MyThread();
			thread.start();
			Thread.sleep(5000);
			// A
			thread.suspend();
			System.out.println("A= " + System.currentTimeMillis() + " i="
					+ thread.getI());
			Thread.sleep(5000);
			System.out.println("A= " + System.currentTimeMillis() + " i="
					+ thread.getI());
			// B
			thread.resume();
			Thread.sleep(5000);

			// C
			thread.suspend();
			System.out.println("B= " + System.currentTimeMillis() + " i="
					+ thread.getI());
			Thread.sleep(5000);
			System.out.println("B= " + System.currentTimeMillis() + " i="
					+ thread.getI());
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 输出结果：
	 * A= 1529049995164 i=2870230141
	   A= 1529050000172 i=2870230141
	   B= 1529050005179 i=5797107797
	   B= 1529050010187 i=5797107797
	 *
	 *通过控制台可以看出，线程的确是被暂停了，而且还可以恢复成运行的状态
	 */

}
